# dataset fashion MNIST
import tensorflow as tf
from tensorflow import keras

print(tf.__version__)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


(train_image, train_label), (test_image, test_label) = tf.keras.datasets.fashion_mnist.load_data()
print(train_image.shape, train_label.shape)
# plt.imshow(train_image[0])
# plt.show()
print(np.max(train_image[0]))
# print(train_label)
train_image = train_image/255.0
test_image = test_image/255.0

Sinput = keras.Input(shape=(28,28))
x = keras.layers.Flatten()(Sinput)
x = keras.layers.Dense(32, activation='relu')(x)
x = keras.layers.Dropout(0.5)(x)
x = keras.layers.Dense(32, activation='relu')(x)

outp = keras.layers.Dense(10, activation='softmax')(x)

model = keras.Model(inputs=Sinput, outputs=outp)

model.summary()

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
              loss='sparse_categorical_crossentropy',
              metrics=['acc'])

history = model.fit(train_image,train_label,epochs=10,
                    validation_data=(test_image, test_label))
# evaluate = model.evaluate(test_image, test_label_onehot)
# print(evaluate)

print(history.history.keys())
plt.plot(history.epoch, history.history.get("loss"), label="loss")
plt.plot(history.epoch, history.history.get("val_loss"), label="val_loss")
plt.legend()
plt.show()

plt.plot(history.epoch, history.history.get("acc"), label="acc")
plt.plot(history.epoch, history.history.get("val_acc"), label="val_acc")
plt.legend()
plt.show()
